package com.share51.admin.result;

import com.share51.admin.exception.Share51Exception;
import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
public class RestResult<T> {

    private int code;

    private String msg;

    private T data;

    public static <T> RestResult success() {
        return new RestResult<T>(200, "success", null);
    }

    public static <T> RestResult<T> success(String msg) {
        return new RestResult<T>(200, msg, null);
    }

    public static <T> RestResult<T> success(T data) {
        return new RestResult<T>(200, "success", data);
    }

    public static <T> RestResult<T> success(String msg, T data) {
        return new RestResult<T>(200, msg, data);
    }

    public static <T> RestResult<T> error(int code, String msg) {
        return new RestResult<T>(code, msg, null);
    }

    public static <T> RestResult<T> error(int code, String msg, T data) {
        return new RestResult<T>(code, msg, data);
    }

    public static <T> RestResult<T> error(int code, T data) {
        return new RestResult<T>(code, null, data);
    }

    public static <T> RestResult<T> error(Share51Exception exception) {
        return new RestResult<T>(exception.getCode(), exception.getMessage(), null);
    }

    public static <T> RestResult<T> error(Share51Exception exception, T data) {
        return new RestResult<T>(exception.getCode(), exception.getMessage(), data);
    }
}
